import request from "@/utils/request";
import type {
  GetSpuListParams,
  GetSpuListResponse,
  GetBaseSaleAttrList,
  AddOrUpdateSpuParams,
  SpuImageList,
  SpuSaleAttrList,
} from "./model/spuModel";
enum Api {
  getSpuList = "/admin/product",
  getBaseSaleAttrList = "/admin/product/baseSaleAttrList",
  addSpu = "/admin/product/saveSpuInfo",
  getSpuImageList = "/admin/product/spuImageList",
  getSpuSaleAttrList = "/admin/product/spuSaleAttrList",
  updateSpu = "/admin/product/updateSpuInfo",
  removeSpu = "/admin/product/deleteSpu",
}

/**
 * 分页获取列表
 * @param page 页码
 * @param limit 每页条数
 * @param category3Id 三级id
 * @returns GetSpuListResponse
 */
export const getSpuListApi = ({
  page,
  limit,
  category3Id,
}: GetSpuListParams) => {
  return request.get<any, GetSpuListResponse>(
    Api.getSpuList + `/${page}/${limit}`,
    {
      params: {
        category3Id,
      },
    }
  );
};

/**
 * 获取基础销售属性列表
 * @returns GetBaseSaleAttrList
 */
export const getBaseSaleAttrListApi = () => {
  return request.get<any, GetBaseSaleAttrList>(Api.getBaseSaleAttrList);
};

/**
 * 添加spu
 * @param data AddOrUpdateSpuParams
 * @returns null
 */
export const addSpuApi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(Api.addSpu, data);
};

/**
 * 获取spu上传图片列表
 * @param spuId
 * @returns SpuImageList
 */
export const getSpuImageListApi = (spuId: number) => {
  return request.get<any, SpuImageList>(Api.getSpuImageList + `/${spuId}`);
};
/**
 * 获取Spu销售属性列表
 * @param spuId
 * @returns SpuSaleAttrList
 */
export const getSpuSaleAttrListApi = (spuId: number) => {
  return request.get<any, SpuSaleAttrList>(
    Api.getSpuSaleAttrList + `/${spuId}`
  );
};

/**
 * 修改spu
 * @param data AddOrUpdateSpuParams
 * @returns null
 */
export const updateSpuApi = (data: AddOrUpdateSpuParams) => {
  return request.post<any, null>(Api.updateSpu, data);
};

/**
 * 删除spu
 * @param spuId spuId
 * @returns null
 */
export const removeSpuApi = (spuId: number) => {
  return request.delete<any, null>(Api.removeSpu + `/${spuId}`);
};
